#define _CRT_SECURE_NO_WARNINGS 1
#include<vector>
#include<queue>
using namespace std;
int numIslands(vector<vector<char>>& grid) {
    int count = 0;
    for (int i = 0; i < grid.size(); i++)
    {
        for (int j = 0; j < grid[0].size(); j++)
        {
            if (grid[i][j] == '1')
            {
                bfs(grid, i, j);
                count++;
            }
        }
    }
    return count;
}
void bfs(vector<vector<char>>& v, int a, int b) {
    int dx[4] = { 0,0,1,-1 };
    int dy[4] = { 1,-1,0,0 };
    queue<pair<int, int>> q;
    q.push({ a,b });

    while (q.size())
    {
        auto p = q.front();
        q.pop();
        int x = p.first;
        int y = p.second;
        v[x][y] = '0';
        for (int i = 0; i < 4; i++)
        {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if (xx >= 0 && yy >= 0 && xx < v.size() && yy < v[0].size() && v[xx][yy] == '1')
            {
                q.push({ xx,yy });
                v[xx][yy] = '0';
            }
        }
    }
}